
var bodyScrollTop = 0;
var rocketTop = 0;
var rocketSum = 0;
var uping_flag = 0;
rocketPosition = document.querySelector(".rocket")

rocketPosition.addEventListener("click", function () {
    bodyScrollTop = document.body.scrollTop || document.documentElement.scrollTop;
    rocketTop = rocketPosition.getBoundingClientRect();
    rocketTop = rocketTop.bottom;
    rocketPosition.classList.add("rocketUping")
    requestAnimationFrame(rocketAndScroll)
})

//火箭 鼠标滚动复原事件
document.querySelector("body").onscroll = function () { scrollRestore(100, 700) }

//火箭与滚动条移动函数
function rocketAndScroll() {
    uping_flag = 1;
    // 需要添加不然 上升时间不为1秒 会跟我停止 滚动条与火箭的条件冲突导致火箭飞去太空
    rocketPosition.style[`transition`] = "all 0s";
    scrollStep = (bodyScrollTop / 60);
    rocketStep = (rocketTop-73) / 60;
    rocketSum += rocketStep;
    console.log(scrollStep, rocketStep)
    if (rocketPosition.getBoundingClientRect().bottom <= 73 && document.documentElement.scrollTop <= 0) {
        uping_flag = 0;
        rocketPosition.classList.remove("rocketUping")
        
        return
    }
    else {
        rocketPosition.style.bottom = rocketSum + "px";
        document.documentElement.scrollTop -= scrollStep;
        requestAnimationFrame(rocketAndScroll)
    }
}

// 鼠标滚动火箭复原执行函数
// arg1 火箭距离  arg2 滚动条距离
function scrollRestore(num1, num2) {
    var scrollDisatance = document.body.scrollTop || document.documentElement.scrollTop;
    if (rocketPosition.getBoundingClientRect().bottom < num1 && uping_flag == 0 && scrollDisatance > num2) {
        rocketPosition.style.bottom = 0 + "px";
        rocketSum = 0;
    }
}